package com.itheima.goods.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.goods.pojo.Brand;
import com.itheima.goods.pojo.Goods;
import com.itheima.goods.service.BrandService;
import entity.PageResult;
//import entity.QueryPageBean;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping
    public List<Brand> findAll() {
        return this.brandService.findAllBrand();
    }

//    @GetMapping("/search/{page}/{size}")
//    public PageResult findPage(@PathVariable("page") Integer page,
//                               @PathVariable("size") Integer size,
//                              ) {
//        return this.brandService.findPage(page, size);
//    }

    @GetMapping("/findPage")
    public PageResult findPage(@RequestParam("currentPage") Integer currentPage,
                               @RequestParam("pageSize") Integer pageSize,
                               @RequestParam(value = "queryString", required = false) String queryString) {
        return this.brandService.findPage(currentPage, pageSize, queryString);
    }

    @PostMapping("/addBrand")
    public Result addBrand(Brand brand) {
        return this.brandService.addBrand(brand);
    }

    @DeleteMapping("/checkitem/{id}")
    public Result delete(@RequestParam("id") Integer id) {
        return this.brandService.deleteBrand(id);
    }

//    @PutMapping("/checkitem")
//    public Result updateBrand(
//            @RequestParam("id") Integer id,
//            @RequestBody Brand brand
//    ) {
//        return this.brandService.updateBrand(brand,id);
//    }

    @PutMapping("/checkitem")
    public Result updateBrand(Brand brand) {
        return this.brandService.updateBrand(brand);
    }

    @GetMapping("{id}")
    public Result findById(@PathVariable("id")Integer id) {

        return this.brandService.findById(id);
    }
}
